<div class="sc_body">
    <form action="{$view['id']?U('save'):U('add')}?spm={$spm}" id="form" class="layui-form layui-form-pane">
        <input type="hidden" name="id" value="{$view.id|default=''}" />
        <div class="sc_title sc_body_title">
            <h5>{$nodeInfo.title}</h5>
            <div class="sc_title_btn">
                <button type="submit" class='layui-btn layui-btn-sm'><i class='layui-icon'>&#xe605;</i> 保存</button>
                <button class='layui-btn layui-btn-sm layui-btn-primary' onclick="window.history.back();return false;"><i class="layui-icon">&#x1006;</i> 返回</button>
            </div>
        </div>
        <div class="fadeInUp animated">
            <section class="sc_layout_inner layui-clear">
                <div class="sc_editor_content">
                    <div class="layui-form-item">
                        <label class="layui-form-label label-required">标题</label>
                        <div class="layui-input-block">
                            <input type="text" name="title" value="{$view.title|default=''}" placeholder="文章标题" datatype="*" nullmsg="请输入标题!" autocomplete="off" class="layui-input" />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">副标题</label>
                        <div class="layui-input-block">
                            <input type="text" name="title_sub" value="{$view.title_sub|default=''}" placeholder="文章副标题" class="layui-input" />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">内容概述</label>
                        <div class="layui-input-block">
                            <textarea name="description" placeholder="内容概述" class="layui-textarea">{$view.description|default=''}</textarea>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">发布时间</label>
                        <div class="layui-input-block">
                            <input type="text" name="create_time" value="{$view.create_time|default=''}" placeholder="当前时间" class="layui-input sc_form_date" readonly="" />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <script name="content" type="text/plain" id="content">{$view.content|htmlspecialchars_decode}</script>
                    </div>
                </div>
                <div class="sc_editor_sidebar">
                    <div class="layui-form-item">
                        <label class="layui-form-label">附属分类</label>
                        <div class="layui-input-block">
                            <select name="nid_other" lay-filter="category">
                                <option value="0">若无需求，可不选！</option>
                                {volist name="category" id="data"}
                                    <option value="{$data.id}" {if condition="$nodeInfo['id'] == $data['id'] || $nodeInfo['mid'] !== $data['mid'] || $data['children'] == 1"}disabled{/if} {$view.nid_other|default=''==$data.id?'selected':''}>{$data.delimiter}{$data.pid?'├':''} {$data.title}</option>
                                {/volist}
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item from_item_image">
                        <div class="img_label">
                            <label>封面图</label>
                            <a id="btn_upload_thumb"></a>
                            <span><i class="layui-icon" data-tips-text="推荐尺寸 720x720">&#xe6b2;</i></span>
                        </div>
                        <div id="thumb_view" class="img_item transition" style="background-image:url('{$view.thumb|default='__Base__/images/noimg.png'}')">
                            <img layer-src="{$view.thumb|default='__Base__/images/noimg.png'}" src="__Base__/images/alpha.png">
                            <input type="hidden" name="thumb" value="{$view.thumb|default=''}">
                        </div>
                    </div>
                    <div class="layui-form-item from_item_image">
                        <div class="img_label">
                            <label>图册</label>
                            <a data-iframe='{:U("uploads/upfile")}?mode=multi&field=photos&type=image'>本地上传</a>
                            <a data-iframe='{:U("uploads/image")}?mode=multi&field=photos' data-title="请选择图片">已上传的</a>
                            <span class="img_tip"></span>
                            <a class="img_edit" data-iframe='{:U("uploads/photos")}?mode=multi&field=photos' data-title="编辑图册">编辑图册</a>
                        </div>
                        <input type="hidden" name="photos" value="{$view.photos|default=''}">
                        <div id="photos_view" class="img_item_box transition nowrap">
                            <div class="img_item transition" style="background-image:url(__Base__/images/noimg.png)">
                                <img layer-src="__Base__/images/noimg.png" src="__Base__/images/alpha.png">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">文章来源</label>
                        <div class="layui-input-block">
                            <input type="text" name="source" value="{$view.source|default='本站'}" placeholder="文章来源" class="layui-input" />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">文章作者</label>
                        <div class="layui-input-block">
                            <input type="text" name="author" value="{$view.author|default='佚名'}" placeholder="文章作者" class="layui-input" />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">原文链接</label>
                        <div class="layui-input-block">
                            <input type="text" name="url" value="{$view.url|default=''}" placeholder="原文链接" class="layui-input" />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">阅读数</label>
                        <div class="layui-input-block">
                            <input type="text" name="count" value="{$view.count|default='0'}" placeholder="阅读数默认为0" class="layui-input" />
                        </div>
                    </div>
                    <div class="layui-form-item" pane="">
                        <label class="layui-form-label">属性</label>
                        <div class="layui-input-block">
                            <input type="checkbox" name="is_status" value="1" title="启用" lay-skin="primary" {eq name="view['is_status']|default='1'" value="1"}checked{/eq} />
                            <input type="checkbox" name="is_recommend" value="1" title="推荐" lay-skin="primary" {eq name="view['is_recommend']|default='0'" value="1"}checked{/eq} />
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </form>
</div>
<script>
    UE.delEditor('content');
    UE.getEditor('content');
    lay('.sc_form_date').each(function(){
        layui.laydate.render({
            elem: this
            ,trigger: 'click'
            ,type: 'datetime'
        });
    });
    //缩略图
    $('body').on('change', '.img_item input', function() {
        var imgInput = $('form').find('[name=' + $(this).attr("name") + ']');
        imgInput.parent('.img_item').css('background-image', 'url(' + this.value + ')');
        imgInput.parent().find('img').attr('layer-src', this.value);
    });
    //图册内容构建
    $('body').on('change', '.from_item_image input', function() {
        var imgInput = $('form').find('[name='+$(this).attr("name")+']');
        var content="";
        if(imgInput.val()!==""){
            var srcs = this.value.split('|');
            $(this).parent().find('.img_tip').html('共 '+srcs.length+' 张');
            $(this).parent().find('.img_edit').show(1000);
            for(var item in srcs){
                content += '<div class="img_item transition" style="background-image:url('+srcs[item]+')"><img layer-src="'+srcs[item]+'" src="__Base__/images/alpha.png"><span>'+(parseInt(item)+1)+'</span></div>';
            }
        }else{
            var content='<div class="img_item transition" style="background-image:url(__Base__/images/noimg.png)"><img layer-src="__Base__/images/noimg.png" src="__Base__/images/alpha.png"></div>';
            $(this).parent().find('.img_edit').hide(1000);
            $(this).parent().find('.img_tip').html('无图片');
        }
        imgInput.next('.img_item_box').html(content);
    });
    //图册初始化
    var Photos = $('form').find('[name=photos]');
    if (Photos.val().length!==0){
        Photos.trigger('change');
    }else{
        Photos.parent().find('.img_edit').hide();
    }
    $(document).ready(function() {
        //图片预览
        layer.photos({photos: '#thumb_view',shade: 0.7,anim: 5});
        layer.photos({photos:'#photos_view', shade:0.7, anim:5});
    });
    $('#btn_upload_thumb').uploadify({
        'swf'      : '/Public/plugs/uploadify/uploadify.swf',
        'uploader' : '{:U("Uploads/upload")}',
        'multi' : false,
        'buttonClass' : '',
        'buttonText' : '本地上传',
        'width' : 110,
        'height' : 36,
        'onUploadSuccess' : function(file, data, response) {
            var allData = eval('(' + data + ')');
            if(allData.status == 1){
                $("#thumb_view").css("background-image","url("+allData.image_src+")");
                $("#thumb_view").find('img').attr('layer-src', allData.image_src);
                $("#thumb_view").find('input').val(allData.image_src);
            }else{
                var timer;
                layer.open({
                    content: allData.info,
                    closeBtn: 0,
                    icon: 2,
                    btn:[],
                    success: function(a,b){
                        var i = 1;
                        var fn = function() {
                            layer.title(i + ' 秒后自动关闭。',b);
                            if(!i) {layer.close(b); return false;} i--;
                        };
                        timer = setInterval(fn, 1000);
                        fn();
                    },
                    cancel: function(i){
                        return false;
                    },
                    end: function(){clearInterval(timer);}
                });
            }
        },
    });
</script>
